# Makefile
# www.voicetronix.com.au
#
# Makefile for Voicetronix "VPB" driver, which supports the following products:
#
# OpenLine4    (V4PCI)
# OpenLog4     (V4LOG)
# OpenSwitch6  (V6PCI)
# OpenSwitch12 (V12PCI)
# OpenLine4i   (VPB4)
# OpenLog8i    (VPB8L)
#
# This makefile used for:
# - compiling and installing the Linux version of the driver
# - compiling and installing the FreeBSD version of the driver
# - building the Linux/FreeBSD/Win32 distro tar-ball.
  
root=/
version=2.2.29
kernelver=`uname -r`
modules=/lib/modules/${kernelver}/kernel/drivers/telephony/

# FreeBSD users: Please change this line to 'OS = FreeBSD'
OS = linux
#OS = FreeBSD
export OS

all:
ifeq ($(OS),linux)
	echo LINUX
	cd src; make
else
	echo FREEBSD
	cd src; gmake
endif

install: all
	mkdir -p $(root)/etc/vpb
	cp -f firmware/vpbmain_isa.out $(root)/etc/vpb
	cp -f firmware/vpbmain_pci.out $(root)/etc/vpb
	cp -f firmware/vlcmain.out $(root)/etc/vpb
	cp -f src/libvpb.a $(root)/usr/local/lib
	cp -f src/vpbapi.h $(root)/usr/include
ifneq ($(OS),linux)
	cp -f FreeBSD/vpb.c /sys/pci
	cp -f FreeBSD/vpbio.h /sys/sys
else
	cp -f src/vpb.o ${modules}
	cp -f src/vpbhp.o ${modules}
endif

clean:	
	rm -f `find . -type f | grep "\.o$$"`
	rm -f src/libvpb.a
	rm -f `find . -type f | grep "\~$$"`
	rm -f `find . -type f | grep "\.bak$$"`
	cd unittest; make clean

	# Microsoft Visual C files we don't need for distro
	rm -f `find . -type f | grep "\.obj$$"`
	rm -f `find . -type f | grep "\.pch$$"`
	rm -f `find . -type f | grep "\.idb$$"`
	rm -f `find . -type f | grep "\.pdb$$"`
	rm -f `find . -type f | grep "\.OPT$$"`
	rm -f `find . -type f | grep "\.ncb$$"`
	rm -f `find . -type f | grep "\.ilk$$"`
	rm -f `find . -type f | grep "\.plg$$"`
	rm -f `find . -type f | grep "\.exp$$"`

doc:
	cd doc; make
cleandoc:	
	cd doc; make clean
unixify:
	# remove ^M's that Windows editors tend to insert - thanks Dave B!
	# run 'make clean' after this to remove .bak files
	perl -pi.bak -e 's/\r$$//' README
	cd src; perl -pi.bak -e 's/\r$$//' *.c *.h *.cpp
	cd unittest; perl -pi.bak -e 's/\r$$//' *.h *.cpp

dist:
	cd doc; make
	rm -f vpb-driver-${version}.tar.gz
	rm -f vpb-driver-${version}-win32.tar.gz
	rm -f vpb-driver-${version}-win32.zip
	rm -f vpb-driver-${version}
	ln -sf . vpb-driver-${version}
	tar --exclude=win32 -czf vpb-driver-${version}.tar.gz vpb-driver-${version}/*
	tar --exclude=*.gz  -czf vpb-driver-${version}-win32.tar.gz vpb-driver-${version}/*
	zip -ry9q vpb-driver-${version}-win32.zip vpb-driver-${version}/* -x  vpb-driver-${version}/vpb-driver-${version}.tar.gz vpb-driver-${version}/vpb-driver-${version}-win32.tar.gz

	rm vpb-driver-${version}







